package com.iknow.view.widget;

import android.content.Context;
import android.media.MediaRecorder;
import android.media.MediaRecorder.OnInfoListener;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import com.iknow.IKnow;
import com.iknow.file.CacheSystem;
import java.io.IOException;

public class RecordingDialog extends FrameLayout
{
  private final String TAG = "RecordingDialog";
  private ImageView mAmImage;
  private String mAudioFile;
  private RecordListener mListener;
  private MediaRecorder mRcorder = new MediaRecorder();
  private FrameLayout mView;
  private MediaRecorder.OnInfoListener recordeInfoListener;

  public RecordingDialog(Context paramContext, RecordListener paramRecordListener)
  {
    super(paramContext);
    this.recordeInfoListener = new MediaRecorder.OnInfoListener(this)
    {
      public void onInfo(, int paramInt1, int paramInt2)
      {
        (paramMediaRecorder.getMaxAmplitude() / 3571);
      }
    };
    ((LayoutInflater)paramContext.getSystemService("layout_inflater"));
    this.mListener = paramRecordListener;
    initView();
  }

  private void initView()
  {
  }

  public void startRecording()
  {
    this.mRcorder.setAudioSource(1);
    this.mRcorder.setOutputFormat(1);
    this.mRcorder.setAudioEncoder(1);
    this.mRcorder.setOnInfoListener(this.recordeInfoListener);
    this.mRcorder.setMaxDuration(60000);
    this.mAudioFile = IKnow.mCacheSystem.createAudioEmptyFile();
    this.mRcorder.setOutputFile(this.mAudioFile);
    try
    {
      this.mRcorder.prepare();
      this.mRcorder.start();
      return;
    }
    catch (IllegalStateException localIllegalStateException)
    {
      if (this.mListener != null)
        this.mListener.onError(localIllegalStateException.getMessage());
      localIllegalStateException.printStackTrace();
    }
    catch (IOException localIOException)
    {
      if (this.mListener != null)
        this.mListener.onError(localIOException.getMessage());
      localIOException.printStackTrace();
    }
  }

  public String stopRecording()
  {
    if (this.mListener != null)
      this.mListener.onCompelete(this.mAudioFile);
    return this.mAudioFile;
  }

  public static abstract interface RecordListener
  {
    public abstract void onCompelete(String paramString);

    public abstract void onError(String paramString);
  }
}